﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/AdminSite.Master"
    Inherits="System.Web.Mvc.ViewPage<Veteran_cms.Models.news_article>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <!-- Validation form -->
    <%using (Html.BeginForm("Create", "ManageNews", new { id = Model.article_id }, FormMethod.Post, new { enctype = "multipart/form-data", @class = "form", id = "validate" }))
      { %>
    <!-- Multiple files uploader -->
    <fieldset>
        <div>
            <div class="widget">
                <div style="float: right">
                    <a href="<%=Url.Action("IndexNews","ManageNews") %>" title="" class="backTo" style="margin: 5px;">
                        <img src="../../images/adminSite/icons/prev.png" alt="" class="icon" /><span>Trở về</span></a></div>
                <div class="title">
                    <img src="../../Images/adminSite/icons/dark/pencil.png" alt="" class="titleIcon" /><h6>
                        Thông tin tin tức - thời sự</h6>
                </div>
                <%if (ViewData["Msg"] != null)
                  {%>
                <div class="nNote nSuccess hideit">
                    <p>
                        <strong>
                            <%=ViewData["Msg"]%></strong></p>
                </div>
                <%} %>
                <div class="formRow">
                    <label>
                        Tiêu đề:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.TextBoxFor(model => model.title, new { @class = "validate[required,maxSize[255]]", id = "req" })%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Tiêu đề:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.TextBoxFor(model => model.sub_title, new { @class = "validate[required,maxSize[255]]", id = "req" })%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Diễn giải:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.TextAreaFor(model => model.description, new { @class = "validate[required", id = "textareaAutoGrow", rows = "4", cols = "" })%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Nội dung:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.TextAreaFor(model => model.content, new { @class = "validate[required]", id = "editor", name = "editor" })%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Tác giả:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.TextBoxFor(model => model.author, new { @class = "validate[required,maxSize[255]]", id = "req" })%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Thư mục cha:<span class="req">*</span></label>
                    <div class="formRight">
                        <%:Html.DropDownListFor(model => model.category_id, ViewData["categoryPanrent"] as SelectList)%></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Hình ảnh large:<span class="req">(353x258)*</span></label>
                    <div class="formRight">
                        <img src="<%=Model.image_large %>" alt="<%=Model.title%>" /></div>
                    <div class="formRight">
                        <input type="file" id="file6" name="uploadFile" /></div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <div class="formRight">
                        <%=Html.CheckBoxFor(mode=>mode.is_hot) %><label for="check1">Tin hot</label>
                    </div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <div class="formRight">
                        <%=Html.CheckBoxFor(mode=>mode.allow_comment) %><label for="check1">Cho phép nhận xét</label>
                    </div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Ngày hiển thị:<span class="req">*</span></label>
                    <div class="formRight">
                        <%=Html.TextBoxFor(mode => mode.show_date, new { @class = "validate[required]", id = "datepicker", name = "datepicker", @readonly = "readonly", Value = String.Format("{0:d}", Model.show_date) })%>
                    </div>
                    <div class="clear">
                    </div>
                </div>
                <div class="formRow">
                    <label>
                        Thuộc tag:<span class="req">*</span></label>
                    <div id="styleautocomplete" class="formRight">
                        <ul id="ulSelected">
                            <li id="liautocomplete">
                                <input type="text" id="name-list" onclick="this.value=''" onkeypress="ResetTextbox(event)"
                                    style="border: 0px; width: 150px; float: none;" /></li>
                        </ul>
                    </div>
                    <div class="clear">
                    </div>
                </div>
            </div>
        </div>
        <div class="widget">
            <%using (Html.BeginForm("Delete", "ManageNews", new { id = Model.article_id }, FormMethod.Post, new { enctype = "multipart/form-data", @class = "form" }))
              { %>
            <div class="formSubmit">
                <input type="submit" value="Xóa" class="redB" /></div>
            <%} %>
            <div class="formSubmit">
                <input type="submit" value="Lưu" class="blueB" /></div>
            <div class="clear">
                <div>
                    <%:Html.HiddenFor(model => model.article_id)%></div>
            </div>
        </div>
        <%} %>
    </fieldset>
    <script src="../../Scripts/admin/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/admin/jquery-ui-1.8.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#name-list").focus();
        });
        function ResetTextbox(e) {
            // look for window.event in case event isn't passed in

            if (window.event) {
                e = window.event;
            }
            var key = e.keyCode || e.which;
            if (key == 13) {

                //alert('i am here key down');
                document.getElementById('name-list').value = "";
            }
        }


        function CreateChildNode(id, name) {
            //create li tag
            var li = document.createElement("li");
            li.setAttribute("id", "li" + id);
            var nodetext = document.createTextNode(name);
            //create image tag
            var img = document.createElement("img");
            img.setAttribute("style", "cursor:pointer");
            img.setAttribute("src", '../../images/adminSite/icons/dark/close.png');
            img.setAttribute("onclick", "RemoveTag(" + id + ")");
            //create hidden input
            var hd = document.createElement("input");
            hd.setAttribute("type", "hidden");
            hd.setAttribute("name", "hd" + id);
            hd.setAttribute("id", "hd" + id);
            hd.setAttribute("value", id);
            //append img,hidden to li tag
            li.appendChild(nodetext);
            li.appendChild(img);
            li.appendChild(hd);
            // reference child
            var refchild = document.getElementById("liautocomplete");
            //append li to ul tag
            document.getElementById("ulSelected").insertBefore(li, refchild);


        }
        $(function () {
            $("#name-list").focusout(ResetValue);
            $("#name-list").click(ResetValue);
        });
        $(function () {

            $("#name-list").autocomplete(

            {

                source: function (request, response) {
                    $.ajax({
                        url: "../../ManageNews/FindTexts", type: "POST", dataType: "json",
                        data: { searchText: request.term, maxResults: 100 },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return { label: item.tag_text, value: item.tag_text, id: item.tag_id }
                            }))
                        }
                    })
                },

                select: function (event, ui) {
                    if (!IsExists(ui.item.id)) {
                        CreateChildNode(ui.item.id, ui.item.label);
                    }
                }

            });

        });

        //check exists
        function IsExists(thisValue) {
            var hdTag = document.getElementById("hd" + thisValue);
            if (hdTag == null)
                return false;
            else
                return true;
        }
        function RemoveTag(thisValue) {
            var ul = document.getElementById("ulSelected");
            var li = document.getElementById("li" + thisValue);
            ul.removeChild(li);
            $("#name-list").focus();
        }
        //reset textbox
        function ResetValue() {
            $("#name-list").val("");
        }
    </script>
</asp:Content>
